package easy;

public class Solution_1394 {

    public int findLucky(int[] arr) {
        int[] counts = new int[501];
        for (int num : arr) {
            counts[num]++;
        }
        for (int i = counts.length - 1; i > 0; i--) {
            if (counts[i] == i) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Solution_1394 model = new Solution_1394();
        System.out.println(model.findLucky(new int[]{2, 2, 3, 4}));
        System.out.println(model.findLucky(new int[]{1, 2, 2, 3, 3, 3}));
        System.out.println(model.findLucky(new int[]{2, 2, 2, 3, 3}));
    }
}
